package com.example.userserver.controller;

import com.example.userserver.enums.ReturnEnum;
import com.example.userserver.params.*;
import com.example.userserver.service.SchoolInfoService;
import com.example.userserver.vo.CityInfoVO;
import com.example.userserver.vo.Result;
import com.example.userserver.vo.SchoolInfoVO;
import com.example.userserver.vo.UserInfoVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/user-server")
@Api(tags = "学校信息接口")
public class SchoolInfoController {
    @Autowired
    private SchoolInfoService schoolInfoService;

    @ApiOperation(value = "获取分页学校")
    @PostMapping(value = "/pageSchool")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<PageInfo<SchoolInfoVO>> pageSchoolInfo(@RequestBody PageSchoolInfoParams pageSchoolInfoParams) {
        return new Result(schoolInfoService.pageSchoolInfo(pageSchoolInfoParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "获取学校列表")
    @GetMapping(value = "/listSchool")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<List<SchoolInfoVO>> listSchoolInfo(@RequestParam(required = false) String cityId) {
        return new Result(schoolInfoService.listSchoolInfo(cityId), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "获取学校")
    @GetMapping(value = "/getSchool")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<SchoolInfoVO> getSchoolInfo(@RequestParam String id) {
        return new Result(schoolInfoService.getSchoolInfo(id), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "删除学校")
    @DeleteMapping(value = "/deleteSchool")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result deleteSchoolInfo(@RequestParam String id) {
        schoolInfoService.deleteSchoolInfo(id);
        return new Result(null, ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "修改学校")
    @PutMapping(value = "/updateSchool")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result updateSchoolInfo(@RequestBody SchoolInfoParams schoolInfoParams) {
        return new Result(schoolInfoService.updateSchoolInfo(schoolInfoParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "新增学校")
    @PostMapping(value = "/insertSchool")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result insertSchoolInfo(@RequestBody SchoolInfoParams schoolInfoParams) {
        return schoolInfoService.insertSchoolInfo(schoolInfoParams);
    }

}
